package com.situ.student.controller.test;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.situ.student.entity.Student;
import com.situ.student.service.IStudentService;
import com.situ.student.service.impl.StudentServiceImpl;

public class ServletContext1 extends HttpServlet{

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//post请求乱码问题
		req.setCharacterEncoding("utf-8");
		//服务器响应浏览器的乱码问题：
		resp.setContentType("text/html;charset=utf-8");
		
		ServletContext servletContext = getServletContext();
		Integer count = (Integer) servletContext.getAttribute("count");
		count++;
		servletContext.setAttribute("count", count);
		
		PrintWriter writer = resp.getWriter();
		writer.println("所有Servlet的访问次数:" + count);
		writer.close();
	}
}
